package com.xhcl.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.core.domain.Stree;
import com.xhcl.common.core.page.TableDataInfo;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.system.domain.TGgYskm;
import com.xhcl.system.service.ITGgYskmService;

/**
 * 预算科目Controller
 * 
 * @author xhcl
 * @date 2020-08-25
 */
@Controller
@RequestMapping("/system/yskm")
public class TGgYskmController extends BaseController
{
    private String prefix = "system/yskm";

    @Autowired
    private ITGgYskmService tGgYskmService;

    @RequiresPermissions("system:yskm:view")
    @GetMapping()
    public String yskm()
    {
        return prefix + "/yskm";
    }

    /**
     * 查询预算科目树列表
     */
    @RequiresPermissions("system:yskm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGgYskm tGgYskm)
    {  
    	startPage();
        List<TGgYskm> list = tGgYskmService.selectTGgYskmList(tGgYskm);
        return getDataTable(list);
    }

    /**
     * 导出预算科目列表
     */
    @RequiresPermissions("system:yskm:export")
    @Log(title = "预算科目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGgYskm tGgYskm)
    {
        List<TGgYskm> list = tGgYskmService.selectTGgYskmList(tGgYskm);
        ExcelUtil<TGgYskm> util = new ExcelUtil<TGgYskm>(TGgYskm.class);
        return util.exportExcel(list, "yskm");
    }

    /**
     * 新增预算科目
     */
    @GetMapping(value = { "/add/{yskm}", "/add/" })
    public String add(@PathVariable(value = "yskm", required = false) String yskm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(yskm))
        {
            mmap.put("tGgYskm", tGgYskmService.selectTGgYskmById(yskm));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存预算科目
     */
    @RequiresPermissions("system:yskm:add")
    @Log(title = "预算科目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGgYskm tGgYskm)
    {
        return toAjax(tGgYskmService.insertTGgYskm(tGgYskm));
    }

    /**
     * 修改预算科目
     */
    @GetMapping("/edit/{yskm}")
    public String edit(@PathVariable("yskm") String yskm, ModelMap mmap)
    {
        TGgYskm tGgYskm = tGgYskmService.selectTGgYskmById(yskm);
        mmap.put("tGgYskm", tGgYskm);
        return prefix + "/edit";
    }

    /**
     * 修改保存预算科目
     */
    @RequiresPermissions("system:yskm:edit")
    @Log(title = "预算科目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGgYskm tGgYskm)
    {
        return toAjax(tGgYskmService.updateTGgYskm(tGgYskm));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:yskm:remove")
    @Log(title = "预算科目", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{yskm}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("yskm") String yskm)
    {
        return toAjax(tGgYskmService.deleteTGgYskmById(yskm));
    }

    /**
     * 选择预算科目树
     */
    @GetMapping(value = { "/selectYskmTree/{yskm}", "/selectYskmTree/" })
    public String selectYskmTree(@PathVariable(value = "yskm", required = false) String yskm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(yskm))
        {
            mmap.put("tGgYskm", tGgYskmService.selectTGgYskmById(yskm));
        }
        return prefix + "/tree";
    }
    
    /**
     * 选择预算科目树
     */
    @GetMapping(value = { "/selectYskmForlbTree/{yskm}", "/selectYskmForlbTree/" })
    public String selectYskmForlbTree(@PathVariable(value = "yskm", required = false) String yskm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(yskm))
        {   TGgYskm tGgYskm=new TGgYskm();
            tGgYskm.setYskm(yskm);
            mmap.put("tGgYskm", tGgYskm);
        }
        return prefix + "/tree";
    }
    
    /**
     * 加载预算科目树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Stree> treeData(String yskm)
    {   TGgYskm tGgYskm=new TGgYskm();
    	tGgYskm.setYskm(yskm);
        List<Stree> ztrees = tGgYskmService.selectTGgYskmTree(tGgYskm);
        return ztrees;
    }
}
